package com.sshc625.utils
	import flash.display.*;
	
	public class SpriteUtil {
		/**
		 * create a new container and add into parent.
		 * 
		 * @parameter cparent container.
		 * @parameter pro  properties for the new container.
		 */
		public static function createAndAddSprite(c:Sprite,pro:Object=null):Sprite {
			return addSpriteCell(c,new Sprite  ,pro);
		}
		/**
		 * create a new container and add into parent.
		 * 
		 * @parameter cparent container.
		 * @parameter pro  properties for the new container.
		 */
		public static function createAndAddMovieClip(c:Sprite,pro:Object=null):MovieClip {
			return addMovieClipCell(c,new MovieClip  ,pro);
		}
		
		/**
		 * Add a new cell which extends Sprite into parent.
		 * 
		 * @parameter c parent container.
		 * @parameter s.
		 * @parameter pro  properties for the new container.
		 */
		public static function addSpriteCell(c:Sprite,s:Sprite,pro:Object=null):Sprite {
			return Sprite(addDisplayObjectCell(c, s, pro));
			
		}
		/**
		 * Add a new cell which extends MovieClip into parent.
		 * 
		 * @parameter c parent container.
		 * @parameter s.
		 * @parameter pro  properties for the new container.
		 */
		public static function addMovieClipCell(c:Sprite,s:MovieClip,pro:Object=null):MovieClip {
			return MovieClip(addDisplayObjectCell(c, s, pro));
		}
		
		/**
		 * 
		 */
		private static function addDisplayObjectCell(c:Sprite,s:*,pro:Object=null):* {
			if (pro != null) {
				for (var p:String in pro) {
					s[p] = pro[p];
				}
			}
			c.addChild(s);
			return s;
		}
	}
}